package com.party.service.study.impl;

import com.party.common.Page;
import com.party.common.Tools;
import com.party.mapper.AnswerMapper;
import com.party.mapper.Curriculum2ContentMapper;
import com.party.mapper.TestMapper;
import com.party.model.*;
import com.party.service.study.Curriculum2contentService;
import com.party.service.study.TestService;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by 011926 on 2014/9/23.
 */
@Repository
public class Curriculum2contentServiceImpl implements Curriculum2contentService
{
    @Resource
    Curriculum2ContentMapper curriculum2ContentMapper;

    @Override
    public int add(Curriculum2Content obj) {
        if(obj != null && obj.getContentid() != null && obj.getContentid() > 0 && obj.getCurriculumid() != null && obj.getCurriculumid() > 0)
        {
            return this.curriculum2ContentMapper.insert(obj);
        }
        return 0;
    }

    @Override
    public int delete(Integer currId,Integer contentId) {
        if(currId != null && currId > 0 && contentId != null && contentId > 0)
        {
            Curriculum2ContentKey key = new Curriculum2ContentKey();
            key.setCurriculumid(currId);
            key.setContentid(contentId);
            return this.curriculum2ContentMapper.deleteByPrimaryKey(key);
        }
        return 0;
    }

    @Override
    public int deleteAllByCurrId(Integer id) {
        if(id != null && id > 0)
        {
            Curriculum2ContentExample example = new Curriculum2ContentExample();
            Curriculum2ContentExample.Criteria criteria = example.createCriteria();
            criteria.andCurriculumidEqualTo(id);
            return this.curriculum2ContentMapper.deleteByExample(example);
        }
        return 0;
    }

    @Override
    public int deleteAllByContentId(Integer id) {
        if(id != null && id > 0)
        {
            Curriculum2ContentExample example = new Curriculum2ContentExample();
            Curriculum2ContentExample.Criteria criteria = example.createCriteria();
            criteria.andContentidEqualTo(id);
            return this.curriculum2ContentMapper.deleteByExample(example);
        }
        return 0;
    }


    @Override
    public List<Curriculum2Content> get(Curriculum2Content obj) {
        if(obj != null )
        {
            Curriculum2ContentExample example = new Curriculum2ContentExample();
            Curriculum2ContentExample.Criteria criteria = example.createCriteria();
            if(obj.getContentid() != null && obj.getContentid() > 0)
            {
                criteria.andContentidEqualTo(obj.getContentid());
            }
            if(obj.getCurriculumid() != null && obj.getCurriculumid() > 0)
            {
                criteria.andCurriculumidEqualTo(obj.getCurriculumid());
            }
            return this.curriculum2ContentMapper.selectByExample(example);
        }
        return null;
    }

//    @Override
//    public int update(Curriculum2Content obj) {
//        return 0;
//    }


}
